package com.medical.data.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medical.data.constEnum.NoticeEnum;
import com.medical.data.domain.Notice;
import com.medical.data.mapper.NoticeMapper;
import com.medical.data.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
@Slf4j
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    /**
     * 通过医生id获取随访通知列表
     * @param doctorId
     * @return
     */
    @Override
    public List<Notice> getFollowUpNotice(String doctorId) {
        LambdaQueryWrapper<Notice> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Notice::getDoctorId,doctorId);
        queryWrapper.eq(Notice::getType, NoticeEnum.FOLLOW_UP_NOTICE.getName());
        return list(queryWrapper);
    }

    /**
     * 已读通知
     * @param noticeIds
     * @return
     */
    @Override
    public boolean readNoticeList(List<String> noticeIds) {
        List<Notice> noticeList=new LinkedList<>();
        if(CollectionUtils.isNotEmpty(noticeIds)){
            noticeIds.stream().forEach(noticeId->{
                Notice byId = getById(noticeId);
                //设置已读
                byId.setHasRead(1);
                noticeList.add(byId);
            });
            return updateBatchById(noticeList);
        }
        return  true;
    }


}
